package com.fastwire.carriere.service;

import javax.jws.WebService;

import com.fastwire.carriere.common.Messages;
import com.fastwire.carriere.common.util.CommonLogger;
import com.fastwire.carriere.controller.HuronController;
import com.fastwire.carriere.controller.impl.HuronControllerImpl;
import com.fastwire.carriere.nas2.vo.SiteVo;
import com.fastwire.carriere.service.dataconverter.XMLConverter;
import com.fastwire.carriere.service.exception.FaultInfo;
import com.fastwire.carriere.service.exception.ServiceException;
import com.fastwire.carriere.service.validator.SiteValidator;

@WebService(endpointInterface = "com.fastwire.carriere.service.NAS2Service")
public class NAS2ServiceImpl implements NAS2Service {

	@Override
	public String createorUpdateSite(SiteVo siteVo) throws ServiceException {

		String msg = Messages.getString("message.common.service.success");

		HuronController controller = new HuronControllerImpl();
		try {

			CommonLogger.info(this, XMLConverter.serilizeObjectToXML(siteVo));
			SiteValidator.validateSiteVo(siteVo);
			controller.createOrUpdateSite(siteVo);
		} catch (Throwable e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage(), new FaultInfo(
					e.getMessage()));
		}
		return msg;
	}

}
